export function ObserverPath(MonitorSdk, _set_) {
  let isHash = window.location.hash //判断是否hash路由
  let _data = _set_.reportData
  let pv = MonitorSdk.sendInfo.behavior
  let pageDuration = pv.pageDuration
  // ps：vue3中的hash路由实际上为history改写，所有通用_Mon_pushState监听，vue2中hash路由可通过hashchange去监听
  if (isHash) {
    let _hash = false
    window.addEventListener('hashchange', function (e) {
      let path = e.oldURL.substring(e.oldURL.indexOf('#')+ 1)
      let _d = {
        ..._data,
        path
      }
      if (pageDuration) pv.pageTime.endTime = performance.now()
      MonitorSdk.sendReports(_d)
      _hash = true
    })
    if (!_hash) _Mon_pushState(MonitorSdk, _data, pv)
  } else {
    _Mon_pushState(MonitorSdk, _data, pv)
  }
}
// 重写history pushState()方法
const _Mon_pushState = (_this, _data, pv) => {
  const _PushState = window.history.pushState;
  window.history.pushState = function (state, title, url) {
    _PushState.apply(this, arguments);
    onPushState(state, title, url);
  };
  // 监听函数
  const onPushState = (state) => {
    if (pv.pageDuration) pv.pageTime.endTime = performance.now()
    let _d = {
      ..._data,
      path:  state.back
    }
    _this.sendReports(_d)
  }
}
